﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shove.Web.UI;

public partial class UserControls_FavoriteGood : UCBase
{
    public UserControls_FavoriteGood()
    {
        Name = "商品收藏";

        swpas = new ShoveWebPartAttribute[20];

        swpas[0] = new ShoveWebPartAttribute_Int("控件宽度", "1,1004", 759, "控件宽度");
        swpas[1] = new ShoveWebPartAttribute_Int("导航单元格高度", "1,500", 23, "导航单元格高度");
        swpas[2] = new ShoveWebPartAttribute_Int("导航单元格宽度", "1,600", 139, "导航单元格宽度");
        swpas[3] = new ShoveWebPartAttribute_Int("图片宽度", "1,600", 200, "图片宽度");
        swpas[4] = new ShoveWebPartAttribute_Int("图片高度", "1,600", 200, "图片高度");

        swpas[5] = new ShoveWebPartAttribute_Color("控件边框颜色", "#E7C890", "控件边框颜色");
        swpas[6] = new ShoveWebPartAttribute_Text("图片CSS样式", "", "photo", "图片CSS样式");

        swpas[7] = new ShoveWebPartAttribute_Image("导航背景图片1", "", "images/UserControls/bg_gold_23.jpg", "导航背景图片1");
        swpas[8] = new ShoveWebPartAttribute_Image("导航背景图片2", "", "images/UserControls/bg_gold_23_2.jpg", "导航背景图片2");

        swpas[9] = new ShoveWebPartAttribute_Text("导航文本样式", "", "Black12", "导航文本样式");
        swpas[10] = new ShoveWebPartAttribute_Text("商品名样式", "", "td14", "商品名样式");
        swpas[11] = new ShoveWebPartAttribute_Text("商品简介样式", "", "td12", "商品简介样式");

        swpas[11] = new ShoveWebPartAttribute_Int("商品名行高", "1,200", 25, "商品名行高");
        swpas[12] = new ShoveWebPartAttribute_Int("每页显示的行数", "1,40", 4, "每页显示的行数");

        swpas[13] = new ShoveWebPartAttribute_Image("删除按钮图片", "", "images/UserControls/b-delete.gif", "删除按钮图片");
        swpas[14] = new ShoveWebPartAttribute_Image("收藏按钮图片", "", "images/UserControls/button_car_5.jpg", "收藏按钮图片");
        swpas[15] = new ShoveWebPartAttribute_Image("查看详细图片", "", "images/UserControls/button_car_6.jpg", "查看详细图片");
        swpas[16] = new ShoveWebPartAttribute_Image("分割线图片", "", "images/UserControls/point_bg.jpg", "分割线图片");

        swpas[17] = new ShoveWebPartAttribute_Text("市场价格样式", "", "market_price", "市场价格样式");
        swpas[18] = new ShoveWebPartAttribute_Text("会员价格样式", "", "blue12", "会员价格样式");
        swpas[19] = new ShoveWebPartAttribute_Text("立即节省价格样式", "", "black12", "立即节省价格样式");
    }

    private void Initlayout()
    {
        //tabctr.Width = swpAttributes[0];
        //tabctr.BgColor = swpAttributes[5];

        //tdsign.Width = swpAttributes[2];
        //tdsign.Height = swpAttributes[1];
        //tdsign.Style.Add("background-image", "url('" + swpAttributes[7] + "')");
        //tdsign.Attributes.Add("class", swpAttributes[9]);

        //tdspace.Style.Add("background-image", "url('" + swpAttributes[8] + "')");
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Initlayout();

        if (_Customer == null)
        {
            Response.Redirect("Default.aspx?PN=Login");
        }
        else
        {
            LoadDataList();
        }
    }

    /// <summary>
    /// 加载收藏商品
    /// </summary>
    private void LoadDataList()
    {
        long ShopID = _Site.ID;
        this.Page1.FindType = 0;
        this.Page1.PageSize = Shove._Convert.StrToInt(swpAttributes[12], 4);
        this.Page1.Field1 = "";
        this.Page1.Field2 = "";
        this.Page1.Like1 = "";
        this.Page1.Like2 = "";

        Page1.DataListID = dlGoods;
        Page1.TableName = "V_Site_FatoviteGood";
        Page1.Condition = "where CustomerID=" + _Customer.ID + " and ShopID=" + ShopID + "";
    }

    /// <summary>
    /// 删除已收藏商品
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void dlGoods_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        HiddenField hID = (HiddenField)e.Item.FindControl("hID");

        new DAL.Tables.tbl_Site_FatoviteGood().Delete("ID=" + hID.Value + "");

        LoadDataList();
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void dlGoods_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        long ShopID = _Site.ID;
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Image img = (Image)e.Item.FindControl("imgGoodPic");
            img.ImageUrl = "~/UpFile/Goods/" + img.ImageUrl;
            img.Width = Shove._Convert.StrToInt(swpAttributes[3], 200);
            img.Height = Shove._Convert.StrToInt(swpAttributes[4], 200);
            img.CssClass = swpAttributes[6];

            HtmlTableCell tdname = (HtmlTableCell)e.Item.FindControl("tdname");
            tdname.Attributes.Add("class", swpAttributes[10]);
            tdname.Height = swpAttributes[11];

            HtmlGenericControl spanvip = (HtmlGenericControl)e.Item.FindControl("spanvip");
            spanvip.Attributes.Add("class", swpAttributes[17]);

            HtmlGenericControl spanmark = (HtmlGenericControl)e.Item.FindControl("spanmark");
            spanmark.Attributes.Add("class", swpAttributes[18]);

            HtmlGenericControl span1 = (HtmlGenericControl)e.Item.FindControl("span1");
            span1.Attributes.Add("class", swpAttributes[19]);

            HtmlTableCell tdcontent = (HtmlTableCell)e.Item.FindControl("tdcontent");
            tdcontent.Attributes.Add("class", swpAttributes[11]);

            HiddenField hGoodID = (HiddenField)e.Item.FindControl("hGoodID");
            ImageButton ibBuy = (ImageButton)e.Item.FindControl("ibBuy");
            ImageButton ibDeletes = (ImageButton)e.Item.FindControl("ibDeletes");
            ibDeletes.ImageUrl = "~/" + swpAttributes[13];
            ibBuy.ImageUrl = "~/" + swpAttributes[14];

            HtmlImage img1 = (HtmlImage)e.Item.FindControl("img1");
            img1.Src = "~/" + swpAttributes[15];

            HtmlTableCell tdline = (HtmlTableCell)e.Item.FindControl("tdline");
            tdline.Style.Add("background-image", "url('" + swpAttributes[16] + "')");

            DataTable dtGood = new DAL.Views.V_Site_GoodShopStock().Open("", "ID=" + hGoodID.Value, "");

            //从收藏夹中删除
            long GoodID = Shove._Convert.StrToLong(hGoodID.Value, 0);
            new DAL.Tables.tbl_Site_FatoviteGood().Delete("GoodID=" + GoodID.ToString() + " and CustomerID=" + _Customer.ID.ToString() + " and ShopID = " + _Site.ID.ToString());

            ibBuy.Attributes.Add("onclick", "addGood('" + hGoodID.Value + "','" + dtGood.Rows[0]["GoodNorm"].ToString() + "','" + dtGood.Rows[0]["GoodColor"].ToString() + "')");
        }
    }
}